<template>
  <!--专业技能-->
  <view>
    <myHead
      :title="title"
      :right="true"
      text_right="保存"
      @clickRight="clickRight"
    ></myHead>
    <view class="conten">
      <view class="li-box fl-lr-c">
        <view class="name">技能名称</view>
        <view>
          <input
            placeholder-class="input_pal"
            v-model="name"
            placeholder="最多输入10个字符"
          />
        </view>
      </view>
      <view class="li-box fl-lr-c">
        <view class="name">使用时长(月)</view>
        <view>
          <u-number-box
            v-model="duration"
            :min="1"
            :max="100"
            @change="numberboxChange"
          ></u-number-box>
        </view>
      </view>

      <u-picker
        :show="show"
        title="掌握程度"
        :columns="list2"
        closeOnClickOverlay
        @close="show = false"
        @cancel="show = false"
        @confirm="degreeChange"
      ></u-picker>

      <view class="li-box fl-lr-c" @click="show = true">
        <view class="name">掌握程度</view>
        <view class="fl-t">
          <view class="content">
            {{ degree.text || "请选择" }}
          </view>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
    </view>

    <bottomBut @bottomBut="bottomBut" v-if="type == 2"></bottomBut>
  </view>
</template>

<script>
import myHead from "@/pages/component/baseHead.vue";
import bottomBut from "@/pages/component/bottomBut.vue";
export default {
  data() {
    return {
      title: "专业技能",
      type: 0, //
      list2: [
        [
          {
            text: "一般",
            value: "1001",
          },
          {
            text: "良好",
            value: "1002",
          },
          {
            text: "精通",
            value: "1003",
          },
          {
            text: "熟练",
            value: "1004",
          },
        ],
      ],
      show: false,
      name: "",
      degree: {
        text: "",
        value: "",
      },
      duration: 1,
      f_id: 0,

      // 当前id
      Id: 0,
      // 父id
      fuid: 0,
    };
  },
  //子组件
  components: {
    myHead,
    bottomBut,
  },
  onLoad(o) {
    this.type = o.type;
    this.fuid = o.fuid;
    if (this.type == 2) {
      let data = JSON.parse(o.data);
      this.Id = data.Id;
      this.name = data.Title;
      this.degree.text = data.Level;
      this.duration = data.UseTime;
    }
  },
  // 计算方法
  methods: {
    clickRight() {
      if (!this.name.length) {
        this.$util.toast("请输入技能名称");
        return;
      }
      if (this.name.length > 10) {
        this.$util.toast("最多输入10个字符");
        return;
      }
      if (!this.degree.text) {
        this.$util.toast("请选择掌握程度");
        return;
      }
      if (this.type == 2) {
        //编辑修改
        let data = {
          Id: this.Id,
          ResumeId: this.fuid,
          Title: this.name,
          UseTime: this.duration,
          Level: this.degree.text,
        };

        this.$http.huirc.resumeproskillup(data).then((res) => {
          if (res.Success) {
            this.$util.toast("保存成功");
            setTimeout(() => {
              uni.navigateBack();
            }, 1000);
          }
        });
      } else {
        let data = {
          ResumeId: this.fuid,
          Title: this.name,
          UseTime: this.duration,
          Level: this.degree.text,
        };
        this.$http.huirc.resumeproskillcr(data).then((res) => {
          if (res.Success) {
            this.$util.toast("保存成功");
            setTimeout(() => {
              uni.navigateBack();
            }, 1000);
          }
        });
      }
    },
    bottomBut() {
      let that = this;
      uni.showModal({
        title: "删除提示",
        content: "确认要删除这条数据",
        success: function (res) {
          if (res.confirm) {
            let data = {
              Id: that.Id,
            };

            that.$http.huirc.resumeproskilldel(data).then((res) => {
              if (res.Success) {
                that.$util.toast("删除成功");
                setTimeout(() => {
                  uni.navigateBack();
                }, 1000);
              }
            });
          }
        },
      });
    },
    degreeChange(e) {
      this.degree = e.value[0];
      this.show = false;
    },
    numberboxChange(e) {
      this.duration = e.value;
    },
  },
};
</script>

<style lang="scss" scoped>
.li-box {
  background-color: #fff;
  .name {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    flex-shrink: 0;
  }

  .logo {
    width: 106rpx;
    height: 106rpx;
    border-radius: 50%;
  }

  .input_pal,
  input,
  .content {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #999999;
    text-align: end;
  }

  .radio-box {
    margin-left: 50rpx;

    .radio-text {
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      padding-left: 20rpx;
    }
  }

  .tui-textarea {
    flex: 1;
  }
}
</style>
